/**
 *
 * Licensed Property to China UnionPay Co., Ltd.
 * 
 * (C) Copyright of China UnionPay Co., Ltd. 2010
 *     All Rights Reserved.
 *
 * 
 * Modification History:
 * =============================================================================
 *   Author         Date          Description
 *   ------------ ---------- ---------------------------------------------------
 *   xshu       2014-05-28       MPI基本参数工具类
 * =============================================================================
 */
package com.unionpay.sdk;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 软件开发工具包 配制
 * 
 * @author xuyaowen
 * 
 */
@Data
@Component("SDKConfig")
public class SDKConfig {

	public static final String FILE_NAME = "acp_sdk.properties";

	/** 前台请求URL. */
	@Value("${unionpay.acpsdk.frontTransUrl}")
	private String frontRequestUrl;

	/** 后台请求URL. */
	@Value("${unionpay.acpsdk.backTransUrl}")
	private String backRequestUrl;

	/** 单笔查询 */
	@Value("${unionpay.acpsdk.singleQueryUrl}")
	private String singleQueryUrl;

	@Value("${unionpay.acpsdk.requestAppUrl}")
	private String requestAppUrl;

	/** 批量交易 */
	@Value("${unionpay.acpsdk.batchTransUrl}")
	private String batchTransUrl;

	/** 文件传输 */
	@Value("${unionpay.acpsdk.fileTransUrl}")
	private String fileTransUrl;

	/** 签名证书路径. */
	@Value("${unionpay.acpsdk.signCert.path}")
	private String signCertPath;

	/** 签名证书密码. */
	@Value("${unionpay.acpsdk.signCert.pwd}")
	private String signCertPwd;

	/** 签名证书类型. */
	@Value("${unionpay.acpsdk.signCert.type}")
	private String signCertType;

	/** 加密公钥证书路径. */
	@Value("${unionpay.acpsdk.encryptCert.path}")
	private String encryptCertPath;

	/** 验证签名公钥证书目录. */
	@Value("${unionpay.acpsdk.validateCert.dir}")
	private String validateCertDir;

	/** 按照商户代码读取指定签名证书目录. */
	private String signCertDir;

	/** 磁道加密证书路径. */
//	@Value("${application.unionpay.acpsdk.encryptTrackCert.path}")
//	private String encryptTrackCertPath;

	/** 磁道加密公钥模数. */
//	@Value("${application.unionpay.acpsdk.encryptTrackKey.modulus}")
//	private String encryptTrackKeyModulus;

//	/** 磁道加密公钥指数. */
//	@Value("${application.unionpay.acpsdk.encryptTrackKey.exponent}")
//	private String encryptTrackKeyExponent;

	/** 有卡交易. */
	@Value("${unionpay.acpsdk.cardTransUrl}")
	private String cardRequestUrl;

/*	*//** app交易 *//*
	@Value("${application.unionpay.acpsdk.appTransUrl}")
	private String appRequestUrl;*/

	/** 证书使用模式(单证书/多证书) */
	@Value("${unionpay.acpsdk.singleMode}")
	private String singleMode;

/*	*//*缴费相关地址*//*
	@Value("${application.unionpay.acpsdk.jfFrontTransUrl}")
	private String jfFrontRequestUrl;

	@Value("${application.unionpay.acpsdk.jfBackTransUrl}")
	private String jfBackRequestUrl;

	@Value("${application.unionpay.acpsdk.jfSingleQueryUrl}")
	private String jfSingleQueryUrl;

	@Value("${application.unionpay.acpsdk.jfCardTransUrl}")
	private String jfCardRequestUrl;

	@Value("${application.unionpay.acpsdk.jfAppTransUrl}")
	private String jfAppRequestUrl;*/


	/** 配置文件中的前台URL常量. */
	public static final String SDK_FRONT_URL = "acpsdk.frontTransUrl";
	/** 配置文件中的后台URL常量. */
	public static final String SDK_BACK_URL = "acpsdk.backTransUrl";
	/** 配置文件中的单笔交易查询URL常量. */
	public static final String SDK_SIGNQ_URL = "acpsdk.singleQueryUrl";
	/** 配置文件中的批量交易查询URL常量. */
	public static final String SDK_BATQ_URL = "acpsdk.batchQueryUrl";
	/** 配置文件中的批量交易URL常量. */
	public static final String SDK_BATTRANS_URL = "acpsdk.batchTransUrl";
	/** 配置文件中的文件类交易URL常量. */
	public static final String SDK_FILETRANS_URL = "acpsdk.fileTransUrl";
	/** 配置文件中的有卡交易URL常量. */
	public static final String SDK_CARD_URL = "acpsdk.cardTransUrl";
	/** 配置文件中的app交易URL常量. */
	public static final String SDK_APP_URL = "acpsdk.appTransUrl";


	/** 以下缴费产品使用，其余产品用不到，无视即可 */
	// 前台请求地址
	public static final String JF_SDK_FRONT_TRANS_URL= "acpsdk.jfFrontTransUrl";
	// 后台请求地址
	public static final String JF_SDK_BACK_TRANS_URL="acpsdk.jfBackTransUrl";
	// 单笔查询请求地址
	public static final String JF_SDK_SINGLE_QUERY_URL="acpsdk.jfSingleQueryUrl";
	// 有卡交易地址
	public static final String JF_SDK_CARD_TRANS_URL="acpsdk.jfCardTransUrl";
	// App交易地址
	public static final String JF_SDK_APP_TRANS_URL="acpsdk.jfAppTransUrl";


	/** 配置文件中签名证书路径常量. */
	public static final String SDK_SIGNCERT_PATH = "acpsdk.signCert.path";
	/** 配置文件中签名证书密码常量. */
	public static final String SDK_SIGNCERT_PWD = "acpsdk.signCert.pwd";
	/** 配置文件中签名证书类型常量. */
	public static final String SDK_SIGNCERT_TYPE = "acpsdk.signCert.type";
	/** 配置文件中密码加密证书路径常量. */
	public static final String SDK_ENCRYPTCERT_PATH = "acpsdk.encryptCert.path";
	/** 配置文件中磁道加密证书路径常量. */
	public static final String SDK_ENCRYPTTRACKCERT_PATH = "acpsdk.encryptTrackCert.path";
	/** 配置文件中磁道加密公钥模数常量. */
	public static final String SDK_ENCRYPTTRACKKEY_MODULUS = "acpsdk.encryptTrackKey.modulus";
	/** 配置文件中磁道加密公钥指数常量. */
	public static final String SDK_ENCRYPTTRACKKEY_EXPONENT = "acpsdk.encryptTrackKey.exponent";
	/** 配置文件中验证签名证书目录常量. */
	public static final String SDK_VALIDATECERT_DIR = "acpsdk.validateCert.dir";

	/** 配置文件中是否加密cvn2常量. */
	public static final String SDK_CVN_ENC = "acpsdk.cvn2.enc";
	/** 配置文件中是否加密cvn2有效期常量. */
	public static final String SDK_DATE_ENC = "acpsdk.date.enc";
	/** 配置文件中是否加密卡号常量. */
	public static final String SDK_PAN_ENC = "acpsdk.pan.enc";
	/** 配置文件中证书使用模式 */
	public static final String SDK_SINGLEMODE = "acpsdk.singleMode";

//	/** 属性文件对象. */
//	private Properties properties;






//	/**
//	 * 从classpath路径下加载配置参数
//	 */
//	public void loadPropertiesFromSrc() {
//		InputStream in = null;
//		try {
//			// Properties pro = null;
//			LogUtil.writeLog("从classpath: " +SDKConfig.class.getClassLoader().getResource("").getPath()+" 获取属性文件"+FILE_NAME);
////			in = SDKConfig.class.getClassLoader()
////					.getResourceAsStream(FILE_NAME);
//			in=new FileInputStream("D:/acp_sdk.properties");
//			if (null != in) {
//				BufferedReader bf = new BufferedReader(new InputStreamReader(
//						in, "utf-8"));
//				properties = new Properties();
//				try {
//					properties.load(bf);
//				} catch (IOException e) {
//					throw e;
//				}
//			} else {
//				LogUtil.writeErrorLog(FILE_NAME + "属性文件未能在classpath指定的目录下 "+SDKConfig.class.getClassLoader().getResource("").getPath()+" 找到!");
//				return;
//			}
//			loadProperties(properties);
//		} catch (IOException e) {
//			LogUtil.writeErrorLog(e.getMessage(), e);
//		} finally {
//			if (null != in) {
//				try {
//					in.close();
//				} catch (IOException e) {
//					LogUtil.writeErrorLog(e.getMessage(), e);
//				}
//			}
//		}
//	}
//
//	/**
//	 * 根据传入的 {@link #load(Properties)}对象设置配置参数
//	 *
//	 * @param pro
//	 */
//	public void loadProperties(Properties pro) {
//		LogUtil.writeLog("开始从属性文件中加载配置项");
//		String value = null;
//		value = pro.getProperty(SDK_SINGLEMODE);
//		if (SDKUtil.isEmpty(value) || SDKConstants.TRUE_STRING.equals(value)) {
//			this.singleMode = SDKConstants.TRUE_STRING;
//			LogUtil.writeLog("单证书模式，使用配置文件配置的私钥签名证书，SingleCertMode:[" + this.singleMode + "]");
//			// 单证书模式
//			value = pro.getProperty(SDK_SIGNCERT_PATH);
//
//			if (!SDKUtil.isEmpty(value)) {
//				this.signCertPath = value.trim();
//				LogUtil.writeLog("配置项：私钥签名证书路径==>"+SDK_SIGNCERT_PATH +"==>"+ value+" 已加载");
//			}
//			value = pro.getProperty(SDK_SIGNCERT_PWD);
//			if (!SDKUtil.isEmpty(value)) {
//				this.signCertPwd = value.trim();
//				LogUtil.writeLog("配置项：私钥签名证书密码==>"+SDK_SIGNCERT_PWD +" 已加载");
//			}
//			value = pro.getProperty(SDK_SIGNCERT_TYPE);
//			if (!SDKUtil.isEmpty(value)) {
//				this.signCertType = value.trim();
//				LogUtil.writeLog("配置项：私钥签名证书类型==>"+SDK_SIGNCERT_TYPE +"==>"+ value+" 已加载");
//			}
//		} else {
//			// 多证书模式
//			this.singleMode = SDKConstants.FALSE_STRING;
//			LogUtil.writeLog("多证书模式，不需要加载配置文件中配置的私钥签名证书，SingleMode:[" + this.singleMode + "]");
//		}
//		value = pro.getProperty(SDK_ENCRYPTCERT_PATH);
//		if (!SDKUtil.isEmpty(value)) {
//			this.encryptCertPath = value.trim();
//			LogUtil.writeLog("配置项：敏感信息加密证书==>"+SDK_ENCRYPTCERT_PATH +"==>"+ value+" 已加载");
//		}
//		value = pro.getProperty(SDK_VALIDATECERT_DIR);
//		if (!SDKUtil.isEmpty(value)) {
//			this.validateCertDir = value.trim();
//			LogUtil.writeLog("配置项：验证签名证书路径(这里配置的是目录，不要指定到公钥文件)==>"+SDK_VALIDATECERT_DIR +"==>"+ value+" 已加载");
//		}
//		value = pro.getProperty(SDK_FRONT_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.frontRequestUrl = value.trim();
//		}
//		value = pro.getProperty(SDK_BACK_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.backRequestUrl = value.trim();
//		}
//		value = pro.getProperty(SDK_BATQ_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.batchQueryUrl = value.trim();
//		}
//		value = pro.getProperty(SDK_BATTRANS_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.batchTransUrl = value.trim();
//		}
//		value = pro.getProperty(SDK_FILETRANS_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.fileTransUrl = value.trim();
//		}
//		value = pro.getProperty(SDK_SIGNQ_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.singleQueryUrl = value.trim();
//		}
//		value = pro.getProperty(SDK_CARD_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.cardRequestUrl = value.trim();
//		}
//		value = pro.getProperty(SDK_APP_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.appRequestUrl = value.trim();
//		}
//		value = pro.getProperty(SDK_ENCRYPTTRACKCERT_PATH);
//		if (!SDKUtil.isEmpty(value)) {
//			this.encryptTrackCertPath = value.trim();
//		}
//
//		/**缴费部分**/
//		value = pro.getProperty(JF_SDK_FRONT_TRANS_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.jfFrontRequestUrl = value.trim();
//		}
//
//		value = pro.getProperty(JF_SDK_BACK_TRANS_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.jfBackRequestUrl = value.trim();
//		}
//
//		value = pro.getProperty(JF_SDK_SINGLE_QUERY_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.jfSingleQueryUrl = value.trim();
//		}
//
//		value = pro.getProperty(JF_SDK_CARD_TRANS_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.jfCardRequestUrl = value.trim();
//		}
//
//		value = pro.getProperty(JF_SDK_APP_TRANS_URL);
//		if (!SDKUtil.isEmpty(value)) {
//			this.jfAppRequestUrl = value.trim();
//		}
//
//		value = pro.getProperty(SDK_ENCRYPTTRACKKEY_EXPONENT);
//		if (!SDKUtil.isEmpty(value)) {
//			this.encryptTrackKeyExponent = value.trim();
//		}
//
//		value = pro.getProperty(SDK_ENCRYPTTRACKKEY_MODULUS);
//		if (!SDKUtil.isEmpty(value)) {
//			this.encryptTrackKeyModulus = value.trim();
//		}
//	}





}
